<?php
//支付宝充值审核
/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use app\models\ChargeCashDeal;
use yii\data\ActiveDataProvider;

$dataProvider = new ActiveDataProvider([
    'query' => ChargeCashDeal::find()->select(['id','money','status','member_id','approve_dt','reg_dt','channel'])->where([
      'type' => ChargeCashDeal::TYPE_CHARGE,
      'channel' => 2
    ])->with('member')->orderBy(['reg_dt'=>SORT_DESC]),
    'pagination' => [
        'pageSize' => 20,
    ],
]);

$this->title = '会员支付宝充值审核';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="page-title">
  <div>
    <h1><i class="fa fa-money"></i> 会员支付宝充值审核</h1>
    <ul class="breadcrumb side">
      <li><i class="fa fa-home fa-lg"></i></li>
      <li>会员充值和提现管理</li>
      <li class="active"><a href="#">会员支付宝充值审核</a></li>
    </ul>
  </div>
</div>

    <div class="card">
      <?php
      //如何提前加载资源
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
    ['class' => 'yii\grid\SerialColumn'],
    'member.realname',
    'reg_dt',
    [
      'header'=>'充值金额',
      'content'=>function ($model, $key, $index, $column) {
        return number_format($model->money,2);
      },
    ],
    [
        'header'=>'审核',
        'content'=>function($model, $key, $index, $column)
        {
          switch($model->status){
            case ChargeCashDeal::STATUS_REGISTER:
            return '<a class="prove_alipay_congzhi" style="cursor:pointer;"><i class="fa fa-lg fa-gavel"></i></a> 正在审核';
            case ChargeCashDeal::STATUS_PROVED:
            return '<i class="fa fa-lg fa-check-circle alert-info"></i> 通过';
            case ChargeCashDeal::STATUS_UNPROVED:
            return '<i class="fa fa-lg fa-times-circle alert-danger"></i> 不通过';
            case ChargeCashDeal::STATUS_DISCARD:
            return '<i class="fa fa-lg fa-trash alert-default"></i> 作废';
            default:
            return '<i class="fa fa-lg fa-trash alert-default"></i> 作废';
          }
        }
    ],
],

]);
?>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header btn-warning">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel"><i class="fa fa-legal"></i> 充值审核</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <!--div class="card"-->
              <section class="invoice">
                <div class="row">
                  <div class="col-xs-12">
                    <h3 class="page-header" ><i class="fa fa-user"></i> <span id='reg_realname'>老虎</span></h3>
                  </div>
                </div>
                <div class="row invoice-info">
                  <div class="col-xs-12">
                    <span class="col-xs-4"><b>充值通道</b></span>
                    <span class="col-xs-8"><b>支付宝</b></span><br><br>
                    <span class="col-xs-4"><b>充值金额</b></span>
                    <span class="col-xs-8" id='reg_money'>302,458</span><br>
                    <span class="col-xs-4"><b>申请日期</b></span>
                    <span class="col-xs-8" id='reg_date'>2017年6月8日</span></div>
                </div>
              </section>
            <!--/div-->
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button id='reg_nopass_submit' type="button" class="btn btn-default" data-dismiss="modal">不通过</button>
        <button id='reg_pass_submit' type="button" class="btn btn-warning" data-dismiss="modal">通过</button>
      </div>
    </div>
  </div>
</div>


<?php $this->beginBlock('prove-js') ?>

  //审核充值
  $('.prove_alipay_congzhi').click(function(){
    var $row=$(this).parents('tr');
    var datakey = $row.attr('data-key');
    var $user = $row.find('td:eq(1)');
    var $date=$row.find('td:eq(2)');
    var $money=$row.find('td:eq(3)');

    $('#reg_realname').text($user.text());
    $('#reg_date').text($date.text());
    $('#reg_money').text($money.text());

    $('#myModal').attr('data-key',datakey);
    $('#myModal').modal();
  });

  $('#reg_nopass_submit').click(function(){
    $.ajax({
      url:"<?=Url::toRoute('site/congzhiproveajax')?>",
      type:"get",
      datatype:"json",
      cache:false,
      data:{
        datakey:$('#myModal').attr('data-key'),
        pass:0
      },
      success:function(data){
         var obj = JSON.parse(data);
         if(obj.errcode===0){
           var datakey = $('#myModal').attr('data-key');
           var $row = $('tr[data-key="'+datakey+'"]');
           var $prove = $row.find('td:eq(4)');
           $prove.html('<i class="fa fa-lg fa-times-circle alert-danger"></i> 不通过');
            $('#myModal').modal('hide');
         }else{
           $('#myModal').modal('hide');
           alert(obj.errmsg);
         }
      },
      error:function(jqXHR,textStatus,errorThrown){
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        $('.compose').slideToggle();
      }
    });
  });

  $('#reg_pass_submit').click(function(){
    $.ajax({
      url:"<?=Url::toRoute('site/congzhiproveajax')?>",
      type:"get",
      datatype:"json",
      cache:false,
      data:{
        datakey:$('#myModal').attr('data-key'),
        pass:1
      },
      success:function(data){
         var obj = JSON.parse(data);
         if(obj.errcode===0){
           var datakey = $('#myModal').attr('data-key');
           var $row = $('tr[data-key="'+datakey+'"]');
           var $prove = $row.find('td:eq(4)');
           $prove.html('<i class="fa fa-lg fa-check-circle alert-info"></i> 通过');
            $('#myModal').modal('hide');
         }else{
           $('#myModal').modal('hide');
           alert(obj.errmsg);
         }
      },
      error:function(jqXHR,textStatus,errorThrown){
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        $('.compose').slideToggle();
      }
    });
  });

<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['prove-js'],\yii\web\View::POS_END); ?>
